package fr.cephb.joperon.structures.bindings;

import com.sleepycat.bind.tuple.TupleInput;
import com.sleepycat.bind.tuple.TupleOutput;

import fr.cephb.berkeley.baseapi.bindings.AbstractTupleBinding;
import fr.cephb.joperon.structures.GTypes;

/**
 * 
 * @author pierre
 *
 */
public class GTypesArrayBinding
	extends AbstractTupleBinding<GTypes[]>
	{
	private int size;
	public GTypesArrayBinding(int size)
		{
		this.size=size;
		}
	
	public int getArraySize()
		{
		return this.size;
		}
	
	@Override
	public GTypes[] entryToObject(TupleInput in)
		{
		GTypes array[]=new GTypes[getArraySize()];
		for( int i=0;i< array.length;++i)
			{
			array[i]=new GTypes(this.readInt16(in));
			}
		return array;
		}

	@Override
	public void objectToEntry(GTypes gtypes[], TupleOutput out)
		{
		if(gtypes.length!=getArraySize()) throw new IllegalArgumentException("length:"+gtypes.length);
		for(GTypes type:gtypes)
			{
			writeInt16(type.getCode(), out);
			}
		}

	}
